<template>
	<view class="page">
		<uni-title type="h1" align="center" title="工资条"></uni-title>
		<view class="list">
			<view class="item">
				<text class="key">姓名</text>
				<text class="value">{{name}}</text>
			</view>
			<view class="item">
				<text class="key">联系号码</text>
				<text class="value">{{account}}</text>
			</view>
			<view class="item">
				<text class="key">邮箱</text>
				<text class="value">{{email}}</text>
			</view>
			<view class="item">
				<text class="key">所在组织</text>
				<text class="value">{{organization}}</text>
			</view>
			<view class="item">
				<text class="key">任职岗位</text>
				<text class="value">{{post}}</text>
			</view>
			<view class="item">
				<text class="key">基本工资</text>
				<text class="value">{{basicSalary}}</text>
			</view>
			<view class="item">
				<text class="key">绩效工资</text>
				<text class="value">{{performance}}</text>
			</view>
			<view class="item">
				<text class="key">保险缴纳</text>
				<text class="value">{{insurances}}</text>
			</view>
			<view class="item">
				<text class="key">积金缴纳</text>
				<text class="value">{{insurances}}</text>
			</view>
			<view class="item">
				<text class="key">奖金</text>
				<text class="value">{{reward}}</text>
			</view>
			<view class="item">
				<text class="key">奖励原因</text>
				<text class="value">{{rewardReason}}</text>
			</view>
			<view class="item">
				<text class="key">扣款</text>
				<text class="value">{{charge}}</text>
			</view>
			<view class="item">
				<text class="key">扣款原因</text>
				<text class="value">{{chargeReason}}</text>
			</view>
			<view class="item">
				<text class="key">实发工资</text>
				<text class="value">{{actual}}</text>
			</view>
			<view class="item">
				<text class="key">发放时间</text>
				<text class="value">{{createTime}}</text>
			</view>
			<button class="save-btn" type="warn" @tap="deleteSalary">删 除</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//当前工资记录id
				id: null,
				//姓名
				name:'',
				//联系号码
				account:'',
				//邮箱
				email:'',
				// 所在组织
				organization:'',
				// 所在岗位
				post:'',
				//基本工资
				basicSalary:'',
				//绩效工资
				performance:'',
				//保险金
				insurances:'',
				//基金
				fund:'',
				//奖金
				reward:'',
				//奖励原因
				rewardReason:'',
				//扣款
				charge:'',
				//扣款原因
				chargeReason:'',
				//实发金额
				actual:'',
				//发放日期
				createTime: ''
			}
		},
		onShow() {
			let that = this;
			uni.setNavigationBarTitle({
				title: '工资单'
			});
			that.loadSalaryInfo(that)
		},
		onLoad: function(options) {
			let that = this;
			that.id = options.id;
			if(options.id==null||options.id==''){
				uni.showToast({
					icon: "error",
					title: "不存在",
					complete: function() {
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							});
						}, 1000)
					}
				})
			}
		},
		methods: {
			//加载工资信息
			loadSalaryInfo(that){
				that.ajax(that.url.searchSalaryById, "POST", {
					"id": that.id
				}, function(resp) {
					let result = resp.data.result;
					let message = '暂无'
					if(result.user.name=='' || result.user.name==null){
						that.name = message;
					}else{
						that.name = result.user.name;
					}
					if(result.user.account == '' || result.user.account == null){
						that.account = message;
					}else{
						that.account = result.user.account;
					}
					if(result.user.email==''||result.user.email==null){
						that.email = message
					}else{
						that.email = result.user.email
					}
					if(result.user.organization == null){
						that.organization = message;
					}else{
						that.organization = result.user.organization.name;
					}
					if(result.user.job == null){
						that.post = message;
					}else{
						that.post = result.user.job.name;
					}
					if(result.basicSalary=='' || result.basicSalary==null){
						that.basicSalary = message;
					}else{
						that.basicSalary = result.basicSalary
					}
					if(result.performance=='' || result.performance==null){
						that.performance = message;
					}else{
						that.performance = result.performance
					}
					if(result.insurances=='' || result.insurances==null){
						that.insurances = message;
					}else{
						that.insurances = result.insurances
					}
					if(result.fund=='' || result.fund==null){
						that.fund = message;
					}else{
						that.fund = result.fund
					}
					if(result.reward=='' || result.reward==null){
						that.reward = message;
					}else{
						that.reward = result.reward
					}
					if(result.rewardReason=='' || result.rewardReason==null){
						that.rewardReason = message;
					}else{
						that.rewardReason = result.rewardReason
					}
					if(result.charge=='' || result.charge==null){
						that.charge = message;
					}else{
						that.charge = result.charge
					}
					if(result.chargeReason=='' || result.chargeReason==null){
						that.chargeReason = message;
					}else{
						that.chargeReason = result.chargeReason
					}
					if(result.actual=='' || result.actual==null){
						that.actual = message;
					}else{
						that.actual = result.actual
					}
					if(result.createTime=='' || result.createTime==null){
						that.createTime = message;
					}else{
						that.createTime = that.formatDataTime(result.createTime)
					}
				})
			},
			deleteSalary: function() {
				let that = this;
				uni.showModal({
					title: '提示信息',
					content: '是否要删除这条消息？',
					success: function(resp) {
						if (resp.confirm) {
							that.ajax(that.url.deleteSalaryById, "DELETE", {
								"id": that.id
							}, function(resp) {
								if(resp.data.code == 20000){
									uni.showToast({
										icon: "success",
										title: "删除成功",
										complete: function() {
											setTimeout(function() {
												uni.navigateBack({
													delta: 1
												});
											}, 1000)
										}
									});
								}
							});
						}
					}
				});
			},
		}
	}
</script>

<style lang="less">
@import url('salary.less');
</style>
